<template>
  <div style="display: flex">
    <Card title="查看场景分类明细" dis-hover icon="md-document" style="flex: 1">
      <Form
        ref="addfrom"
        :model="FormData"
        :rules="FormRules"
        :label-width="140"
      >
        <Row>
          <Col span="18" offset="3">
            <FormItem label="场景分类名称：">
              <span>{{ FormData.categoryName }}</span>
            </FormItem>
          </Col>
          <Col span="18" offset="3">
            <FormItem label="位置：">
              <span>{{ FormData.position }}</span>
            </FormItem>
          </Col>
          <Col span="18" offset="3">
            <FormItem label="是否启用：">
              <RadioGroup v-model="FormData.categoryState">
                <Radio label="1" disabled>启用</Radio>
                <Radio label="2" disabled>禁用</Radio>
              </RadioGroup>
            </FormItem>
          </Col>
          <Col span="18" offset="3">
            <FormItem label="备注：">
              <span>{{ FormData.categoryDesc }}</span>
            </FormItem>
          </Col>
          <Col span="18" offset="3">
            <FormItem>
              <!-- <Button type="primary" @click="handleSubmit('FormData')">提交</Button> -->
              <Button @click="handleReset('FormData')" class="ivu-ml-8"
                >返回</Button
              >
            </FormItem>
          </Col>
        </Row>
      </Form>
    </Card>
  </div>
</template>
<script>
import { mapState, mapMutations } from 'vuex';
import util from '@/libs/util';
import { ApiRequest } from '@api/basePage';
import { myTreeDataUtils } from '@/assets/js/commonUtils';

export default {
  components: {},
  data () {
    return {
      multipledata: false,
      isRootCategory: false,
      showRight: false,
      showCategory: true,
      util: util,
      dynamicData: {},
      pagePath: '', // 当前路由
      FormRules: {},
      FormData: {
        categoryName: '',
        categoryDesc: '',
        levelNum: '',
        position: '',
        categoryState: '',
        uuid: '',
        parentUuid: '',
        version: ''
      },
      rootDate: [],
      uuid: ''
    };
  },
  watch: {
    $route: function () {
      this.$nextTick(() => {
        this.$router.go(0);
      });
    }
  },
  created () {
    this.getConfigData();
    this.initData();
  },
  mounted () {},
  methods: {
    // 获取初始配置信息
    getConfigData () {
      this.pagePath = this.$route.path;
      let dynamicData = require('./configjs/sceneModelManageAdd').default;
      this.requestApi = dynamicData.requestApi; // 页面所需接口集合
      this.$set(this.$data, 'dynamicData', dynamicData);
      this.uuid = this.$route.query.uuid;
    },
    // 初始化数的数据
    initData () {
      let data = {
        uuid: this.uuid
      };
      // 初始化
      ApiRequest(
        this.requestApi.baseGetByUuid.url,
        this.requestApi.baseGetByUuid.type,
        data,
        true
      ).then(res => {
        if (res.retStatus === '1') {
          this.FormData.categoryName = res.retData.categoryName;
          this.FormData.categoryNo = res.retData.categoryNo;
          this.FormData.categoryDesc = res.retData.categoryDesc;
          this.FormData.position = res.retData.position;
          this.FormData.categoryState = res.retData.categoryState;
          this.FormData.levelNum = res.retData.levelNum;
          this.FormData.parentUuid = res.retData.parentUuid;
          this.FormData.uuid = res.retData.uuid;
          this.FormData.version = res.retData.version;
        }
      });
    },
    handleSubmit (FormData) {
      if (this.FormData.categoryName === '') {
        this.$Message.error('请填写分类名称');
        return;
      }
      if (this.FormData.categoryState === '') {
        this.$Message.error('请选择是否启用');
        return;
      }
      let data = {
        parentUuid: this.FormData.parentUuid,
        categoryName: this.FormData.categoryName,
        categoryDesc: this.FormData.categoryDesc,
        position: this.FormData.position,
        categoryState: this.FormData.categoryState,
        uuid: this.FormData.uuid,
        version: this.FormData.version,
        levelNum: this.FormData.levelNum
      };
      // 创建分类
      ApiRequest(
        this.requestApi.updatePlatCategory.url,
        this.requestApi.updatePlatCategory.type,
        data,
        false
      ).then(res => {
        if (res.retStatus === '1') {
          this.initData();
          this.$Message.success('提交成功');
        }
      });
    },
    clearData () {
      this.FormData.uuid = '';
      this.FormData.categoryName = '';
      this.FormData.categoryDesc = '';
      this.FormData.categoryNo = '';
      this.FormData.position = '';
    },
    handleReset () {
      this.$router.go(-1);
    },
    treeSelectChange (arr, item) {
      this.FormData.uuid = item.uuid;
      if (item.levelNum === '3') {
        this.multipledata = true;
        this.showRight = true;
        this.showCategory = true;
      } else if (item.levelNum === '4') {
        this.showRight = false;
        this.showCategory = false;
      } else {
        this.multipledata = false;
        this.showRight = true;
        this.showCategory = true;
      }
    }
  }
};
</script>
